package com.example.ws.handler.elog;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

public class LocalELogCache {
    private static LocalELogCache instance = new LocalELogCache();
    
    private static final LinkedList<ELogEntity> cqueue = new LinkedList<>();
    
    private static int MAX_SIZE = 10000;

    private LocalELogCache() {}
    public static LocalELogCache getInstance() {
        return instance;
    }

    public void add(ELogEntity e) {
        cqueue.add(e);
        if (cqueue.size() > MAX_SIZE) {
            cqueue.removeFirst();
        }
    }

    public void addAll(List<ELogEntity> elogs) {
        System.out.println("log size +> " + elogs.size());
        cqueue.addAll(elogs);
        while (cqueue.size() > MAX_SIZE) {
            cqueue.removeFirst();
        }
    }

    // todo
    public List<ELogEntity> fromToEnd(int pos) {
        return cqueue;
    }

}
